#include <stdio.h>
#define N_MAX 100001

/* {{{ heapmgr */
void
swap_int(int* a, int* b)
{
	int T;
	T  = *a;
	*a = *b;
	*b =  T;
}



void
Heap_sort__sift_down(int * array, int start, int end)
{
	int parent = start,
	    child,
	    swap;

	while (parent * 2 + 1 <= end) {
		child = parent * 2 + 1;
		swap = parent;

		if (array[swap] < array[child])
			swap = child;

		if (child+1 <= end && array[swap] < array[child+1])
			swap = child+1;

		if (swap != parent) {
			swap_int(&array[parent], &array[swap]);
			parent = swap;
		} else {
			return;
		}
	}
}



void
Heap_sort__heapify(int* array, int size)
{
	int start = size / 2 - 1;

	while (start >= 0) {
		Heap_sort__sift_down(array, start--, size - 1);
	}
}



void
Heap_sort__sift_up(int * array, int start, int end)
{
	int child = end,
	    parent = (end - 1) / 2;

	/*
	 * 'start' is a kind of left barrier for this function
	 */
        while (child > start) {
		if (array[(child - 1) / 2] < array[child]) {
			swap_int(&array[parent], &array[child]);
			child = parent;
			parent = (child - 1) / 2;
			/*Could look like this:
			 * child = parent--;
			 * parent /= 2;
			 */
		} else
			return;
	}
}
/* }}} */


static void
ExtractMax(int* array, int size)
{
	swap_int(&array[0], &array[size-1]); /* deleting max */
	--size;
	printf("%d\n", array[size]);
	/*
	 * Must decrement n (size) somewhere.
	 */
	Heap_sort__sift_down(array, 0, size-1);
}



static void
Insert(int x, int* array, int size)
{
	array[size++] = x;
	Heap_sort__sift_up(array, 0, size - 1);
}



int
main(void)
{
	int array[N_MAX], size = 0;
	register int i = 0;
	int op = -1,	/* operation code */
	    n,		/* amount of operations */
	    x;		/* what were inserting */
	freopen("pqueue.in", "rt", stdin);
	freopen("pqueue.out", "w", stdout);

	(void)scanf("%d", &n);
	while (i < n) {
		(void) scanf("%d", &op);
		switch (op) {
			case 1:
				ExtractMax(array, size);
				--size;
				break;
			case 0:
				(void)scanf("%d", &x);
				Insert(x, array, size);
				++size;
				break;
		}
		++i;
	}
	return 0;
}
/* vim: foldmethod=marker:
 */
